
export const lineOptions = (params, machineTypeId, date) => {
  let dataTime = []
  let diftenDayAst = []
  let oneDayAst = []
  let tenDayAst = []
  let baseTT = []
  params.forEach((item) => {
    dataTime.push(item.dataTime.slice(5))
    diftenDayAst.push(item.diftenDayAst)
    oneDayAst.push(item.oneDayAst)
    tenDayAst.push(item.tenDayAst)
    baseTT.push(item.baseTT)
  })

  // const categoryData = ['23/09/01', '23/09/05', '23/09/06', '23/09/07', '23/09/08', '23/09/09', '23/09/10', '23/09/11', '23/09/12', '23/09/13', '23/09/14', '23/09/15', '23/09/16', '23/09/17', '23/09/18', '23/09/19', '23/09/20', '23/09/21', '23/09/22', '23/09/23', '23/09/24', '23/09/25', '23/09/26', '23/09/27', '23/09/28', '23/09/29', '23/09/30', '23/10/01', '23/10/02', '23/10/03', '23/10/04', '23/10/05', '23/10/06']
  // const data1_1 = [2.76, 2.72, 2.82, 2.8, 2.9, 2.8, 2.84, 2.8, 2.78, 2.86, 2.86, 2.9, 2.82, 2.78, 2.8, 2.84, 2.82, 2.86, 2.82, 2.76, 2.74, 2.74, 2.74, 2.72, 2.76, 2.72, 2.4, 2.74, 2.28, 2.76, 2.73, 2.72, 2.76]
  // const data2_1 = [2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72, 2, 2.72, 2.72, 2.72, 2.72, 2.72, 2.72]
  // const data2_2 = [0.15, 0.12, 0.2, 0.2, 0.24, 0.18, 0.2, 0.16, 0.16, -0.08, 0.2, 0.18, 0.18, 0.18, 0.18, 0.2, 0.18, 0.18, 0.2, 0.16, 0.14, 0.14, 0.12, 0.12, 0.15, 0.12, 0.2, 0.16, 0.12, 0.18, 0.14, 0.13, 0.19]

  const lineOption = {
    title: {
      text: `${machineTypeId}群 AST_10D 基准日别趋势（${date}）`,
      textStyle: {
        fontSize:'16px',
        fontWeight: 500
      }
    },
    // 图例
    legend: {
      right: '50',
      data: [ 'AST_10D差异', 'AST_1D', 'AST_10D', '基准值']
    },
    // 提示框组件
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross'
      },
      borderWidth: 1,
      borderColor: '#ccc',
      padding: 10,
      textStyle: {
        color: '#000',
        fontSize: 12
      },
      formatter: function(params) {
        let str = ''
        params.forEach((item, idx, arr) => {
          if(item.seriesType === 'candlestick'){
            str += `${item.axisValue}<br/>${item.marker}${item.seriesName}`
          } else {
            if(Array.isArray(item.data)){
              str += `${item.axisValue}<br/>${item.marker}${item.seriesName}<span style="float: right;">${item.data[1]}</span>`
            } else {
              str += `${item.marker}${item.seriesName}<span style="float: right; margin-left: 50px;">${item.data}</span>`
            }
          }
          if(Array.isArray(item.data) && item.seriesType !== 'bar'){
            str += `
              <br/> <span style="display:inline-block;margin-left:6px;margin-right:4px;border-radius:6px;width:6px;height:6px;background-color:${item.color};"></span> Q1 <span style="float: right;">${item.color === '#ec0000' ? item.data[1] : item.data[2]}</span>

              <br/> <span style="display:inline-block;margin-left:6px;margin-right:4px;border-radius:6px;width:6px;height:6px;background-color:${item.color};"></span> 中位 <span style="float: right;">${item.color === '#ec0000' ? item.data[2] : item.data[1]}</span>

              <br/> <span style="display:inline-block;margin-left:6px;margin-right:4px;border-radius:6px;width:6px;height:6px;background-color:${item.color};"></span> 最小 <span style="float: right;">${item.data[3]}</span>

              <br/> <span style="display:inline-block;margin-left:6px;margin-right:4px;border-radius:6px;width:6px;height:6px;background-color:${item.color};"></span> Q3 <span style="float: right;">${item.data[4]}</span>
              
              
              `
          }
          str += idx === params.length - 1 ? '': '<br/>'
        })
        return str
      }
    },
    axisPointer: {
      link: [
        {
          xAxisIndex: 'all'
        }
      ],
      label: { // 文本标签的背景颜色
        backgroundColor: '#777'
      }
    },
    toolbox: {
      feature: {
        saveAsImage: {}, // 保存图片
        brush: {
          type: ['']
        }
      }
    },
    grid: [
      {
        left: '4%',
        right: '0',
        height: '15%'
      },
      {
        left: '4%',
        right: '0',
        top: '45%',
        height: '35%',
        bottom: '0'
      }
    ],
    xAxis: [
      {
        type: 'category',
        data: dataTime,
        boundaryGap: true, // 两边留白策略
        axisTick: {
          show: false // 不显示坐标轴刻度线
        },
        axisLine: {
          show: false // 不显示坐标轴线
        },
        axisLabel: {
          show: false // 不显示坐标轴上的文字
        },
        min: 'dataMin',
        max: 'dataMax',
        axisPointer: {
          z: 100
        }
      },
      {
        type: 'category',
        gridIndex: 1,
        data: dataTime,
        boundaryGap: true,
        axisLine: { onZero: false },
        axisTick: { show: false },
        min: 'dataMin',
        max: 'dataMax',
        axisLabel: {
          interval: 0, //隔几项显示一个标签
          rotate: "45" //标签倾斜的角度，旋转的角度是-90到90度
        }
      }
    ],
    yAxis: [
      {
        splitArea: {
          // show: true
        },
        splitLine: { show: false },
        interval: 0.2, // 指定刻度间隔
        min:'dataMin', //取最小值为最小刻度
        max: 'dataMax' //取最大值为最大刻度
      },
      {
        gridIndex: 1,
        splitNumber: 2,
        splitLine: { show: false },
        interval: 0.2, // 指定刻度间隔
        min:function (value) {
          return (value.min - 0.1).toFixed(2)
        }, //取最小值为最小刻度
        max: 'dataMax' //取最大值为最大刻度
      }
    ],
    series: [
      {
        name: 'AST_10D差异',
        type: 'bar',
        data: diftenDayAst,
        smooth: true,
        lineStyle: {
          opacity: 0.5
        },
        label: { // 文字描述
          show: true,
          position: 'top', // 在上方显示
          textStyle: { // 数值样式
            fontSize: 12
          },
          formatter: function (data) { // 描述文字的字体颜色变化
            if (data.value < 0) {
              return '{a|' + data.value  + '}'
            } else {
              return '{b|' + data.value + '}'
            }
          },
          rich: {
            a: {
              color: '#000'
            },
            b: {
              color: 'red'
            }
          }
        }
      },
      {
        name: 'AST_1D',
        type: 'line',
        data: oneDayAst,
        smooth: true,
        xAxisIndex: 1,
        yAxisIndex: 1,
        lineStyle: {
          opacity: 0.5
        }
      },
      {
        name: 'AST_10D',
        type: 'line',
        smooth: true, // 平滑折线
        xAxisIndex: 1,
        yAxisIndex: 1,
        data: tenDayAst
      },
      {
        name: '基准值',
        type: 'line',
        smooth: true, // 平滑折线
        symbol: 'none',
        xAxisIndex: 1,
        yAxisIndex: 1,
        data: baseTT
      }
    ]
  }

  return {
    lineOption
  }
}